<script>
	export default {
		globalData: {
			pre_url: '',
			baseurl: '',
			session_id: '',
			aid: 0,
			mid: 0,
			pid: 0,
			needAuth: 0,
			platform: 'wx',
			platform2: '',
			isdouyin: 0,
			sysset: [],
			indexurl: '/pages/index/index',
			menudata: [],
			menu2data: [],
			currentIndex: -1,
			initdata: {},
			textset: [],
			isinit: false,
			socketOpen: false,
			socket_token: '',
			socketMsgQueue: [],
			socketConnecttimes: 0,
			scene: 0,
			homeNavigationCustom: 0,
			usercenterNavigationCustom: 0,
			navigationBarBackgroundColor: '#ffffff',
			navigationBarTextStyle: 'black',
		},
		onLaunch: function(options) {
			var extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {};
			if (extConfig && extConfig.aid) {
				this.globalData.aid = extConfig.aid;
				this.globalData.pre_url = extConfig.baseurl;
				this.globalData.homeNavigationCustom = extConfig.homeNavigationCustom || 0;
				this.globalData.usercenterNavigationCustom = extConfig.usercenterNavigationCustom || 0;
				this.globalData.navigationBarBackgroundColor = extConfig.navigationBarBackgroundColor || '#ffffff';
				this.globalData.navigationBarTextStyle = extConfig.navigationBarTextStyle || 'black';
			} else {
				var siteInfo = require("./siteinfo.js");
				this.globalData.aid = siteInfo.uniacid;
				this.globalData.pre_url = siteInfo.siteroot;
				this.globalData.homeNavigationCustom = siteInfo.homeNavigationCustom || 0;
				this.globalData.usercenterNavigationCustom = siteInfo.usercenterNavigationCustom || 0;
				this.globalData.navigationBarBackgroundColor = siteInfo.navigationBarBackgroundColor || '#ffffff';
				this.globalData.navigationBarTextStyle = siteInfo.navigationBarTextStyle || 'black';
			}
			this.globalData.baseurl = this.globalData.pre_url + '/?s=/';
			this.globalData.session_id = uni.getStorageSync('session_id');
			var opts = this.getopts(options.query);
			if (opts && opts.pid) {
				this.globalData.pid = opts.pid;
			}
			// #ifdef APP-PLUS
			this.globalData.platform = 'app';
			var app = this;
			uni.getSystemInfo({
				success: function(res) {
					app.globalData.platform2 = res.platform;
				}
			})
			// #endif
			// #ifdef H5
			this.globalData.platform = 'h5';
			if (navigator.userAgent.indexOf('MicroMessenger') > -1) {
				this.globalData.platform = 'mp';
			}
			// #endif
			// #ifdef MP-WEIXIN
			this.globalData.platform = 'wx';
			this.checkUpdateVersion();
			// #endif
			// #ifdef MP-ALIPAY
			this.globalData.platform = 'alipay';
			// #endif
			// #ifdef MP-BAIDU
			this.globalData.platform = 'baidu';
			// #endif
			// #ifdef MP-TOUTIAO
			this.globalData.platform = 'toutiao';
			var sysinfo = tt.getSystemInfoSync();
			if (sysinfo.appName == 'Douyin') {
				this.globalData.isdouyin = 1;
			}
			// #endif
			// #ifdef MP-QQ
			this.globalData.platform = 'qq';
			// #endif
			console.log(this.globalData.platform);
		},
		onShow: function(options) {
			var that = this;
			console.log('onShow');
			console.log(options);
			console.log('---------xxxx');
			if (options && options.scene) {
				this.globalData.scene = options.scene;
			}
			// #ifdef MP-WEIXIN
			// share card/Subscribe to news/Scan the QR code/advertise/The circle of friends and other scenes can be calledgetShareParamsThe interface gets the following parameters
			const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155];
			if (sceneList.includes(this.globalData.scene)) {
				console.log('---------00')
				try {
					let livePlayer = requirePlugin('live-player-plugin');
					console.log(livePlayer)
					console.log('---------11');
					livePlayer.getShareParams().then(res => {
						let custom_params = res.custom_params;
						console.log(custom_params)
						if (custom_params && custom_params.pid) {
							that.globalData.pid = custom_params.pid;
						}
					}).catch(err => {
						console.log('get share params err ', err);
					});
				} catch (e) {
					console.log('live-player-plugin err ', e);
				}
			}
			// #endif
		},
		methods: {
			getopts: function(opt) {
				if (opt && opt.scene) {
					var scene = opt.scene
					var scenes = scene.split('-');
					var opts = {};
					for (var i in scenes) {
						var thisscenes = scenes[i].split('_');
						opts[thisscenes[0]] = thisscenes[1];
					}
					return opts;
				} else {
					return opt
				}
			},
			alert: function(content, confirmfun) {
				uni.showModal({
					title: 'prompt information',
					showCancel: false,
					confirmText: 'OK',
					content: content.toString(),
					success: function(res) {
						if (res.confirm) {
							typeof confirmfun == 'function' && confirmfun();
						}
					}
				});
			},
			confirm: function(content, confirmfun, cancelfun) {
				uni.showModal({
					title: 'Confirmation of operation',
					content: content.toString(),
					showCancel: true,
					cancelText: 'Cancel',
					confirmText: 'OK',
					success: function(res) {
						if (res.confirm) {
							typeof confirmfun == 'function' && confirmfun();
						} else {
							typeof cancelfun == 'function' && cancelfun();
						}
					}
				});
			},
			success: function(title, successfun) {
				if (undefined == title) title = 'Operation succeeded';
				var title = title.toString();
				uni.showToast({
					title: title,
					icon: (title.length > 8 ? 'none' : 'success'),
					success: function(res) {
						typeof successfun == 'function' && successfun();
					}
				});
			},
			error: function(title, duration) {
				if (title === false) {
					uni.hideToast();
				} else {
					if (this.isNull(duration)) duration = 2500;
					if (undefined == title) title = 'The operation failed';
					uni.showToast({
						title: title.toString(),
						icon: 'none',
						duration: duration
					});
				}
			},
			showLoading: function(title) {
				if (title === false) {
					uni.hideLoading();
				} else {
					if (undefined == title) title = 'Loading';
					uni.showLoading({
						title: title.toString(),
						mask: true
					});
				}
			},
			inArray: function(search, array) {
				for (var i in array) {
					if (array[i] == search) {
						return true;
					}
				}
				return false;
			},
			isNull: function(e) {
				return e == undefined || e == "undefined" || e == null || e == "";
			},
			parseJSON: function(e) {
				try {
					return JSON.parse(e);
				} catch (t) {
					return undefined;
				}
			},
			getparams: function(url) {
				if (url.indexOf('?') === -1) return {};
				var query = url.split('?')[1];
				var vars = query.split("&");
				var params = {};
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					params[pair[0]] = pair[1];
				}
				return params;
			},
			goto: function(tourl, opentype) {
				var app = this;
				var params = app.getparams(tourl);
				console.log(params);
				if (params && params.reloadthispage == 1) {
					var thispage = getCurrentPages().pop();
					thispage.$vm.opt = params;
					thispage.$vm.getdata();
					return;
				}
				if (app.isNull(opentype) && tourl) {
					//var currentIndex = -1;
					var tablist = app.globalData.menudata['list'];
					if (tablist) {
						for (var i = 0; i < tablist.length; i++) {
							if (tablist[i]['pagePath'] == tourl) {
								opentype = 'reLaunch';
							}
						}
					}
				}
				if (tourl.indexOf('pages/') === 0) tourl = '/' + tourl;
				if (app.globalData.isdouyin == 1 && tourl.indexOf('/pages/shop/product') === 0) {
					app.showLoading('Loading');
					app.post('ApiShop/getDouyinProductId', {
						proid: params.id
					}, function(res) {
						app.showLoading(false);
						if (res.status == 1) {
							tt.openEcGood({
								promotionId: res.douyin_product_id,
								fail: function(res2) {
									app.alert(res2.errMsg)
								}
							});
						} else {
							app.alert(res.msg)
						}
					});
					return;
				}
				if (app.globalData.platform == 'wx' && tourl.indexOf('https://work.weixin.qq.com/kfid/') === 0) {
					wx.openCustomerServiceChat({
						extInfo: {
							url: tourl
						},
						corpId: app.globalData.initdata.corpid
					});
					return;
				}
				if (tourl == 'scan::') {
					if (app.globalData.platform == 'h5') {
						app.alert('Please use WeChat scan function to scan the code');
						return;
					} else if (app.globalData.platform == 'mp') {
						var jweixin = require('jweixin-module');
						jweixin.ready(function() { //It needs to be called before the user may click the share button
							jweixin.scanQRCode({
								needResult: 0, // Default is0，Scan results are processed by WeChat，1 returns the scan result directly，
								scanType: ["qrCode",
									"barCode"
								], // You can specify whether to scan a QR code or a 1D code，Both are by default
								success: function(res) {
									var content = res
										.resultStr; // when needResult is 1，Scan code returned results
									//app.goto(content);
								}
							});
						});
					} else {
						uni.scanCode({
							success: function(res) {
								console.log(res);
								if (res.path) {
									app.goto('/' + res.path);
								} else {
									var content = res.result;
									app.goto(content);
								}
							}
						});
					}
					return;
				}
				if (tourl == 'share::') {
					if (app.globalData.platform == 'h5' || app.globalData.platform == 'mp') {
						app.error('Click on the upper right corner to send to friends or share to friends circle');
					}
					if (app.globalData.platform == 'app') {
						uni.showActionSheet({
							itemList: ['Send to WeChat friends', 'Share to WeChat Moments'],
							success: function(res) {
								if (res.tapIndex >= 0) {
									var scene = 'WXSceneSession';
									if (res.tapIndex == 1) {
										scene = 'WXSenceTimeline';
									}
									var sharedata = {};
									sharedata.provider = 'weixin';
									sharedata.type = 0;
									sharedata.scene = scene;
									sharedata.title = app.globalData.initdata.name;
									var fullurl = app._fullurl();
									if (app.globalData.mid > 0) {
										fullurl += (fullurl.indexOf('?') === -1 ? '?' : '&') + 'pid=' + app
											.globalData.mid
									}
									sharedata.href = app.globalData.pre_url + '/h5/' + app.globalData.aid +
										'.html#' + fullurl;
									sharedata.imageUrl = app.globalData.initdata.logo;
									sharedata.summary = app.globalData.initdata.desc;
									uni.share(sharedata);
								}
							}
						});
					}
					return;
				}
				if (!tourl || tourl == 'contact::' || tourl == 'share::') return;
				if (tourl.indexOf('tel::') === 0) {
					//Call up
					tourl = tourl.slice(5);
					uni.makePhoneCall({
						phoneNumber: tourl
					});
					return;
				}
				if (tourl.indexOf('tel:') === 0) {
					//Call up
					tourl = tourl.slice(4);
					uni.makePhoneCall({
						phoneNumber: tourl
					});
					return;
				}
				if (tourl.indexOf('url::') === 0) { //external link
					if (app.globalData.platform == 'h5' || app.globalData.platform == 'mp') {
						location.href = tourl.slice(5);
					} else {
						tourl = '/pages/index/webView?url=' + encodeURIComponent(tourl.slice(5));
					}
				}
				if (tourl.indexOf('https://') === 0 || tourl.indexOf('http://') === 0) { //external link
					if (app.globalData.platform == 'h5' || app.globalData.platform == 'mp') {
						location.href = tourl;
					} else {
						tourl = '/pages/index/webView?url=' + encodeURIComponent(tourl);
					}
				}
				if (tourl.indexOf('miniProgram::') === 0) {
					//Other applet
					tourl = tourl.slice(13);
					var tourlArr = tourl.split('|'); //console.log(tourlArr)

					uni.navigateToMiniProgram({
						appId: tourlArr[0],
						path: tourlArr[1] ? tourlArr[1] : '',
						complete: function() {
							if (tourlArr[2]) {
								app.goto(tourlArr[2]);
							}
						}
					});
					return;
				}
				if (tourl == 'getmembercard::') {
					//Receive membership card
					app.post('ApiCoupon/getmembercardparam', {
						card_id: ''
					}, function(res) {
						if (res.status == 0) {
							app.alert(res.msg);
							return;
						}
						if (app.globalData.platform == 'wx') {
							uni.navigateToMiniProgram({
								appId: 'wxeb490c6f9b154ef9',
								// fixed to this appid，immutable
								extraData: res.extraData,
								// include encrypt_card_id outer_str bizThree Fields，The parameters must be obtained from the link obtained in step3
								success: function() {},
								fail: function() {},
								complete: function() {}
							});
						} else {
							location.href = res.ret_url;
						}
					});
					return;
				}
				if (tourl.indexOf('location::') === 0) {
					//Coordinate navigation
					tourl = tourl.slice(10);
					var tourlArr = tourl.split('|');
					var jwd = tourlArr[1].split(',');
					uni.openLocation({
						latitude: parseFloat(jwd[1]),
						longitude: parseFloat(jwd[0]),
						name: tourlArr[0],
						scale: 13
					});
					return;
				}
				if (tourl.indexOf('plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin') === 0) {
					//Mini Program Live with parameters
					tourl = tourl + '&custom_params=' + encodeURIComponent(JSON.stringify({
						pid: app.globalData.mid
					}));
				}
				if (app.isNull(opentype)) {
					var mv = tourl.split("?");
					var urlpath = mv[0];
					if (app.globalData.platform == 'h5' && urlpath == app._fullurl()) {
						opentype = 'reLaunch';
					} else {
						opentype = 'navigate';
					}
				}
				if (opentype == 'switchTab') {
					var args = new Object();
					var name, value;
					var url = tourl; //Jump link
					var num = url.indexOf("?");
					if (num >= 0) {
						var urlbase = url.substr(0, num);
						var str = url.substr(num + 1); //get all parameters

						var arr = str.split("&"); //Put each parameter in an array

						for (var i = 0; i < arr.length; i++) {
							num = arr[i].indexOf("=");

							if (num > 0) {
								name = arr[i].substring(0, num);
								value = arr[i].substr(num + 1);
								args[name] = value;
							}
						}
						uni.switchTab({
							url: urlbase,
							success: function(e) {
								var page = getCurrentPages().pop();
								if (page == undefined || page == null) return;
								page.onLoad(args);
							}
						});
					} else {
						uni.switchTab({
							url: tourl
						});
					}
				} else if (opentype == 'redirect' || opentype == 'redirectTo') {
					uni.redirectTo({
						url: tourl
					});
				} else if (opentype == 'reLaunch') {
					uni.reLaunch({
						url: tourl
					});
				} else {
					var pages = getCurrentPages();

					if (pages.length >= 10) {
						uni.redirectTo({
							url: tourl
						});
					} else {
						uni.navigateTo({
							url: tourl
						});
					}
				}
			},
			goback: function(isreload) {
				var app = this;
				var pages = getCurrentPages();
				if (isreload && pages.length > 1) {
					var prePage = pages[pages.length - 2];
					prePage.$vm.getdata();
				}
				if (pages.length == 1) {
					app.goto(app.globalData.indexurl, 'reLaunch');
				} else {
					uni.navigateBack({
						fail: function() {
							app.goto(app.globalData.indexurl, 'reLaunch');
						}
					});
				}
			},
			post: function(url, param, callback) {
				this.request('POST', url, param, callback);
			},
			get: function(url, param, callback) {
				this.request('GET', url, param, callback);
			},
			request: function(method, url, param, callback) {
				var oldurl = url;
				var app = this;
				if (url.substring(0, 8) != 'https://') {
					url = app.globalData.baseurl + url;
					url += (url.indexOf('?') > 0 ? '&' : '?') + 'aid=' + app.globalData.aid + '&platform=' + app
						.globalData.platform + '&session_id=' + app.globalData.session_id + '&pid=' + app.globalData
						.pid;
					if (app.globalData.isdouyin == 1) {
						url += '&isdouyin=1';
					}
					if (!app.globalData.isinit) {
						url += '&needinit=1';
					}
				}
				uni.request({
					url: url,
					//Just an example, not a real interface address
					data: param,
					method: method,
					success: function(res) {
						app.setinitdata(res);
						if (res.data && res.data.status == -1) { //Jump to login page
							app.showLoading(false);
							var pages = getCurrentPages();
							var currentPage = pages[pages.length - 1];
							currentPage.$vm.loading = false;
							var frompage = '';
							var nowurl = app._url();
							var opentype = 'reLaunch';
							if (app.globalData.platform == 'baidu') {
								if (nowurl == '/pages/my/usercenter') {
									opentype = 'redirect';
								} else {
									opentype = 'navigate';
								}
							}
							if (nowurl != '/pages/index/login' && nowurl != '/pages/index/reg' && nowurl !=
								'/pages/index/getpwd') {
								var frompage = encodeURIComponent(app._fullurl());
							}
							if (res.data.authlogin == 1) {
								app.authlogin(function(res2) {
									if (res2.status == 1) {
										if (res2.msg) app.success(res2.msg);
										currentPage.$vm.getdata();
									} else if (res2.status == 2) {
										app.goto('/pages/index/login?frompage=' + frompage +
											'&logintype=4&login_bind=1', opentype);
									} else {
										console.log(res2);
										app.goto('/pages/index/login?frompage=' + frompage,
											opentype);
									}
								});
							} else {
								app.goto('/pages/index/login?frompage=' + frompage, opentype);
								return;
							}
						} else if (res.data && res.data.status == -10) { //Jump administrator login
							app.showLoading(false);
							var pages = getCurrentPages();
							var currentPage = pages[pages.length - 1];
							currentPage.$vm.loading = false
							//Admin login
							app.goto('/admin/index/login', 'redirect');
						} else if (res.data && res.data.status == -2) { //Official account or h5 jump
							app.showLoading(false);
							var pages = getCurrentPages();
							var currentPage = pages[pages.length - 1];
							currentPage.$vm.loading = false
							//jump
							location.href = res.data.url
						} else if (res.data && res.data.status == -3) { //Jump to the specified page
							app.showLoading(false);
							var pages = getCurrentPages();
							var currentPage = pages[pages.length - 1];
							currentPage.$vm.loading = false
							//jump
							app.goto(res.data.url, 'redirect');
						} else if (res.data && res.data.status == -
							4) { //Pop-up prompt and jump to the specified page
							app.showLoading(false);
							var pages = getCurrentPages();
							var currentPage = pages[pages.length - 1];
							currentPage.$vm.loading = false
							//popup prompt
							app.alert(res.data.msg, function() {
								if (res.data.url) {
									app.goto(res.data.url, 'redirect');
								}
							});
						} else {
							typeof callback == "function" && callback(res.data);
						}
					},
					fail: function(res) {
						try {
							if (oldurl != 'ApiIndex/linked') {
								if (res.errMsg != 'request:fail timeout') {
									console.log(res);
									//app.alert('Request failed：' + JSON.stringify(res));
								}
							}
						} catch (e) {}
					}
				});
			},
			authlogin: function(callback, params) {
				var app = this;
				if (app.globalData.platform == 'wx') {
					wx.getUserProfile({
						lang: 'zh_CN',
						desc: 'Used to display avatar nickname',
						success: function(res2) {
							console.log(res2)
							var userinfo = res2.userInfo;
							wx.login({
								success(res1) {
									var code = res1.code;
									app.post('ApiIndex/wxlogin', {
										code: code,
										userinfo: userinfo,
										pid: app.globalData.pid
									}, function(res) {
										typeof callback == "function" && callback(res);
									});
								}
							});
						},
						fail: function(res2) {
							console.log(res2)
							if (res2.errMsg == 'getUserProfile:fail auth deny') {

							} else {
								typeof callback == "function" && callback({
									status: 0,
									msg: res2.errMsg
								});
							}
						}
					});
				} else if (app.globalData.platform == 'mp' || app.globalData.platform == 'h5') {
					var frompage = '';
					var nowurl = app._url();
					if (nowurl != '/pages/index/login' && nowurl != '/pages/index/reg' && nowurl !=
						'/pages/index/getpwd') {
						frompage = encodeURIComponent(app._fullurl());
					}
					if (params && params.frompage) {
						frompage = params.frompage;
					}
					location.href = app.globalData.pre_url + '/index.php?s=ApiIndex/shouquan&aid=' + app.globalData
						.aid + '&session_id=' + app.globalData.session_id + '&pid=' + app.globalData.pid +
						'&frompage=' + encodeURIComponent(frompage);
				} else if (app.globalData.platform == 'app') {
					plus.oauth.getServices(function(services) {
						console.log(services)
						let s = services[0]
						for (var i in services) {
							var service = services[i];
							if (service.id == 'weixin') {
								s = service;
							}
						}
						console.log(s)
						console.log('x----')
						s.authorize(function(e) {
							console.log(e);
							var code = e.code;
							app.post('ApiIndex/appwxlogin', {
								code: code,
								pid: app.globalData.pid
							}, function(res) {
								typeof callback == "function" && callback(res);
							});
						});
					});
				} else if (app.globalData.platform == 'baidu') {
					swan.getLoginCode({
						success: res => {
							console.log('getLoginCode success', res);
							var code = res.code;
							app.post('ApiIndex/baidulogin', {
								code: code,
								pid: app.globalData.pid
							}, function(res) {
								typeof callback == "function" && callback(res);
							});
						},
						fail: err => {
							typeof callback == "function" && callback({
								status: 0,
								msg: err.errMsg
							});
						}
					});
				} else if (app.globalData.platform == 'qq') {
					qq.login({
						success(res) {
							if (res.code) {
								app.post('ApiIndex/qqlogin', {
									code: res.code,
									pid: app.globalData.pid
								}, function(res) {
									typeof callback == "function" && callback(res);
								});
							} else {
								typeof callback == "function" && callback({
									status: 0,
									msg: res.errMsg
								});
							}
						},
						fail(res) {
							typeof callback == "function" && callback({
								status: 0,
								msg: res.errMsg
							});
						}
					})
				} else if (app.globalData.platform == 'toutiao') {
					tt.login({
						force: true,
						success(res) {
							if (res.code) {
								app.post('ApiIndex/toutiaologin', {
									code: res.code,
									pid: app.globalData.pid
								}, function(res) {
									typeof callback == "function" && callback(res);
								});
							} else {
								typeof callback == "function" && callback({
									status: 0,
									msg: res.errMsg
								});
							}
						},
						fail(res) {
							typeof callback == "function" && callback({
								status: 0,
								msg: res.errMsg
							});
						}
					})
				} else if (app.globalData.platform == 'alipay') {
					my.getAuthCode({
						scopes: 'auth_base',
						success: (res) => {
							console.log(res)
							if (res.authCode) {
								app.post('ApiIndex/alipaylogin', {
									code: res.authCode,
									pid: app.globalData.pid
								}, function(res) {
									typeof callback == "function" && callback(res);
								});
							}
						},
						fail: (res) => {
							typeof callback == "function" && callback({
								status: 0,
								msg: res.errMsg
							});
						}
					});
				}
			},
			setinitdata: function(res) {
				var app = this;
				var oldmid = app.globalData.mid;
				if (res && res.data && (res.data.mid || res.data.mid === 0) && app.globalData.mid != res.data.mid) {
					app.globalData.mid = res.data.mid;
					if (res.data.session_id) {
						uni.setStorageSync('session_id', res.data.session_id);
						app.globalData.session_id = res.data.session_id;
					}
					if (app.globalData.mid) {
						app.globalData.socket_token = res.data.socket_token
						app.openSocket();
					}
				}
				if (res && res.data && res.data._initdata) {
					app.globalData.isinit = true;
					res.data._initdata.pre_url = app.globalData.pre_url;
					app.globalData.initdata = res.data._initdata;
					app.globalData.mid = res.data._initdata.mid;
					app.globalData.isdouyin = res.data._initdata.isdouyin;
					uni.setStorageSync('session_id', res.data._initdata.session_id);
					app.globalData.session_id = res.data._initdata.session_id;
					if (app.globalData.platform == 'mp') {
						var share_package = res.data.share_package;
						var jweixin = require('jweixin-module');
						jweixin.config({
							debug: false,
							appId: share_package.appId,
							timestamp: share_package.timestamp,
							nonceStr: share_package.nonceStr,
							signature: share_package.signature,
							jsApiList: [
								'checkJsApi',
								'onMenuShareAppMessage',
								'onMenuShareTimeline',
								'updateAppMessageShareData',
								'updateTimelineShareData',
								'chooseImage',
								'previewImage',
								'uploadImage',
								'openLocation',
								'getLocation',
								'closeWindow',
								'scanQRCode',
								'chooseWXPay',
								'addCard',
								'chooseCard',
								'openCard'
							],
							'openTagList': ['wx-open-launch-weapp']
						});
					}
					if (app.globalData.mid) {
						app.globalData.socket_token = res.data.socket_token
						app.openSocket();
					}
				}
				if (app.globalData.mid && app.globalData.mid != oldmid) {
					if (app.globalData.platform == 'wx') {
						wx.login({
							success: function(res) {
								if (res.code) {
									app.post('ApiIndex/setwxopenid', {
										code: res.code
									}, function() {})
								}
							}
						});
					} else if (app.globalData.platform == 'alipay') {
						my.getAuthCode({
							scopes: ['auth_base'],
							success: (res) => {
								if (res.authCode) {
									app.post('ApiIndex/setalipayopenid', {
										code: res.authCode
									}, function() {})
								}
							},
						});
					} else if (app.globalData.platform == 'baidu') {
						swan.getLoginCode({
							success: (res) => {
								if (res.code) {
									app.post('ApiIndex/setbaiduopenid', {
										code: res.code
									}, function() {})
								}
							},
							fail: err => {
								console.log('getLoginCode fail', err);
							}
						});
					}
				}

			},
			//enable socket connection
			openSocket: function() {
				console.log('openSocket');
				//#ifndef MP-TOUTIAO
				var app = this;
				if (app.globalData.platform != 'toutiao') {
					uni.closeSocket();
				}
				uni.connectSocket({
					url: (app.globalData.pre_url).replace('https://', "wss://") + '/wss'
				});
				uni.onSocketOpen(function(res) {
					app.globalData.socketOpen = true;
					for (var i = 0; i < app.globalData.socketMsgQueue.length; i++) {
						app.sendSocketMessage(app.globalData.socketMsgQueue[i]);
					}
					app.globalData.socketMsgQueue = [];
				});
				app.sendSocketMessage({
					type: 'khinit',
					data: {
						aid: app.globalData.aid,
						mid: app.globalData.mid,
						platform: app.globalData.platform
					}
				});
				setInterval(function() {
					app.sendSocketMessage({
						type: 'connect'
					});
				}, 25000);
				uni.onSocketMessage(function(res) {
					console.log('Receive server content：' + res.data);
					try {
						var data = JSON.parse(res.data);
						var needpopup = true;
						var pages = getCurrentPages();
						var currentPage = pages[pages.length - 1];
						if (!currentPage) return;
						console.log(currentPage.$vm.hasOwnProperty('receiveMessage'));
						if (currentPage && currentPage.$vm.hasOwnProperty('receiveMessage')) {
							console.log(data);
							var rs = currentPage.$vm.receiveMessage(data);
							needpopup = !rs;
						}
						if (needpopup && (data.type == 'tokefu' || data.type == 'tokehu' || data.type ==
								'peisong' || data.type == 'notice')) { //Pop-up prompt is required
							currentPage.$vm.$refs.popmsg.open(data);
						}
					} catch (e) {}
				});
				//#endif
			},
			sendSocketMessage: function(msg) {
				var app = this;
				if (!msg.token) msg.token = this.globalData.socket_token;
				if (this.globalData.socketOpen) {
					console.log(msg);
					uni.sendSocketMessage({
						data: JSON.stringify(msg),
						fail: function() {
							if (app.globalData.socketConnecttimes < 1) {
								app.globalData.socketConnecttimes++;
								app.globalData.socketMsgQueue.push(msg);
								console.log('openSocket Reconnection');
								app.openSocket();
							}
						}
					});
				} else {
					this.globalData.socketMsgQueue.push(msg);
				}
			},
			chooseImage: function(callback, count) {
				var app = this;
				uni.chooseImage({
					count: count || 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: function(res) {
						var tempFilePaths = res.tempFilePaths,
							imageUrls = [];

						for (var i = 0; i < tempFilePaths.length; i++) {
							app.showLoading('uploading');
							uni.uploadFile({
								url: app.globalData.baseurl + 'ApiImageupload/uploadImg/aid/' + app
									.globalData.aid + '/platform/' + app.globalData.platform +
									'/session_id/' +
									app.globalData.session_id,
								filePath: tempFilePaths[i],
								name: 'file',
								success: function(res) {
									app.showLoading(false);
									var data = JSON.parse(res.data);

									if (data.status == 1) {
										imageUrls.push(data.url);

										if (imageUrls.length == tempFilePaths.length) {
											typeof callback == 'function' && callback(
												imageUrls);
										}
									} else {
										app.alert(data.msg);
									}
								},
								fail: function(res) {
									app.showLoading(false);
									app.alert(res.errMsg);
								}
							});
						}
					},
					fail: function(res) { //alert(res.errMsg);
					}
				});
			},
			getLocation: function(callback1, callback2) {
				if (this.globalData.platform == 'mp') {
					var jweixin = require('jweixin-module');
					jweixin.ready(function() {
						jweixin.getLocation({
							type: 'gcj02',
							success: function(res) {
								typeof callback1 == 'function' && callback1(res);
							},
							fail: function(res) {
								typeof callback2 == 'function' && callback2(res);
							}
						});
					});
				} else if (this.globalData.platform == 'alipay') {
					uni.getLocation({
						success: function(res) {
							typeof callback1 == 'function' && callback1(res);
						},
						fail: function(res) {
							typeof callback2 == 'function' && callback2(res);
						}
					});
				} else {
					uni.getLocation({
						type: 'gcj02',
						success: function(res) {
							typeof callback1 == 'function' && callback1(res);
						},
						fail: function(res) {
							typeof callback2 == 'function' && callback2(res);
						}
					});
				}
			},
			setCache: function(key, value) {
				return uni.setStorageSync(key, value);
			},
			getCache: function(key) {
				return uni.getStorageSync(key);
			},
			removeCache: function(key) {
				var $ = this;
				if ($.isNull(key)) {
					uni.clearStorageSync();
				} else {
					uni.removeStorageSync(key);
				}
			},
			_url: function() {
				//get current pageurl
				var pages = getCurrentPages(); //Get the loaded page
				var currentPage = pages[pages.length - 1]; //Get the object of the current page
				var url = '/' + (currentPage.route ? currentPage.route : currentPage.__route__); //current page url 
				return url;
			},
			_fullurl: function() {
				var pages = getCurrentPages(); //Get the loaded page
				var currentPage = pages[pages.length - 1]; //Get the object of the current page
				var url = '/' + (currentPage.route ? currentPage.route : currentPage.__route__); //current page url 
				var opts = currentPage.$vm.opt;
				console.log(opts)
				var params = [];
				for (var i in opts) {
					params.push(i + '=' + opts[i]);
				}
				if (params.length > 0) {
					url += '?' + params.join('&');
				}
				console.log(url)
				return url;
			},
			checkUpdateVersion() {
				if (wx.canIUse('getUpdateManager')) {
					//Create an instance of UpdateManager
					const updateManager = wx.getUpdateManager();
					//console.log('Whether to enter the simulation update');
					//Check for version updates
					updateManager.onCheckForUpdate(function(res) {
						//console.log('whether to get version');
						// Callback after requesting new version information
						if (res.hasUpdate) {
							//Monitor the applet for version update events
							updateManager.onUpdateReady(function() {
								//TODO The new version has been downloaded，transfer applyUpdate Apply the new version and restart （ The automatic update operation is performed here）
								updateManager.applyUpdate();
							})
							updateManager.onUpdateFailed(function() {
								// Failed to download new version
								//wx.showModal({
								//	title: 'There is already a new version~',
								//	content: 'Please delete the current applet，to WeChat “Discovery - applet” Page，Search again to open~',
								//})
							})
						}
					})
				} else {
					//TODO At this time, the WeChat version is too low (generally the version is supported）
					//wx.showModal({
					//  title: 'Kind tips',
					//  content: 'The current WeChat version is too low to use this function, please upgrade to the latest WeChat version and try again。'
					//})
				}
			},
		}
	};
</script>
<style>
	@import "./common.css";
	@import "./iconfont.css";
	@import '@/components/parse/parse.css';
</style>
